//
//  JifenDetailViewController.m
//  jizhiyunduan
//
//  Created by 鞠超 on 16/4/27.
//  Copyright © 2016年 JC. All rights reserved.
//

#import "JifenDetailViewController.h"

@interface JifenDetailViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;

//cell
@property (nonatomic, strong) UILabel * lbl_text1;
@property (nonatomic, strong) UILabel * lbl_text2;
@property (nonatomic, strong) UILabel * lbl_text3;

@end

@implementation JifenDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _lblTitle.text = [NSString stringWithFormat:@"积分详情列表"];
    _lblTitle.font = [UIFont systemFontOfSize:20];
    
    _btnRight.hidden = YES;
    
    [self addLeftButton:@"fanhui@2x.png"];
}

//左返回
- (void)clickLeftButton:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//隐藏tabbar
-(void)viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void)p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
    //刷新
    __unsafe_unretained UITableView *tableView = self.tableView;
    __unsafe_unretained __typeof(self) weakSelf = self;
    
    // 下拉刷新
    tableView.mj_header= [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        // 结束刷新
        [tableView.mj_header endRefreshing];
    }];
    
    // 马上进入刷新状态
    [tableView.mj_header beginRefreshing];
    
    // 设置自动切换透明度(在导航栏下面自动隐藏)
    tableView.mj_header.automaticallyChangeAlpha = YES;
    
//    // 上拉加载
//    tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
//
//        // 结束刷新
//        [tableView.mj_footer endRefreshing];
//    }];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat list_x = (SCREEN_WIDTH - 10) / 4;
    
    UITableViewCell * cell = [[UITableViewCell alloc] init];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //1
    self.lbl_text1 = [[UILabel alloc] initWithFrame:CGRectMake(5 , 10, list_x * 1.5, 25)];
    self.lbl_text1.text = [NSString stringWithFormat:@"  兑换奖品",indexPath.row + 1];
    self.lbl_text1.textColor = [UIColor blackColor];
    self.lbl_text1.font = [UIFont systemFontOfSize:13];
    [cell addSubview:self.lbl_text1];
    
     
    //2
    self.lbl_text2 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 1.5, 10, list_x * 1, 25)];
    self.lbl_text2.text = [NSString stringWithFormat:@"- %d",(indexPath.row + 10)* 2];
    self.lbl_text2.textColor = [UIColor greenColor];
    self.lbl_text2.textAlignment = NSTextAlignmentCenter;
    self.lbl_text2.font = [UIFont systemFontOfSize:13];
    [cell addSubview:self.lbl_text2];
    
    
    //3
    self.lbl_text3 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 2.5, 10, list_x * 1.5, 25)];
    self.lbl_text3.text = [NSString stringWithFormat:@"2016-12-%d 12:%d",indexPath.row + 1,indexPath.row + 10];
    self.lbl_text3.textColor = [UIColor blackColor];
    self.lbl_text3.font = [UIFont systemFontOfSize:13];
    self.lbl_text3.textAlignment = NSTextAlignmentCenter;
    [cell addSubview:self.lbl_text3];
    
    
//    UIImageView * image = [[UIImageView alloc] initWithFrame:CGRectMake(5 + list_x * 4 + 2.5, 12.5, 20, 20)];
//    image.image = [UIImage imageNamed:@"youfanhui.png"];
//    [cell addSubview:image];
    
    //赋值
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    //总View
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
    view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    //扣费记录列表
    UIView * view_bg1 = [[UIView alloc] initWithFrame:CGRectMake(0, 1, SCREEN_WIDTH, 35)];
    view_bg1.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    
    CGFloat list_x = (SCREEN_WIDTH - 10) / 4;
    
    UILabel * list_1 = [[UILabel alloc] initWithFrame:CGRectMake(5 , 7.5, list_x * 1.5, 20)];
    list_1.text = @"  积分消费记录";
    list_1.textColor = navi_bar_bg_color;
    list_1.font = [UIFont systemFontOfSize:13];
    //    list_1.textAlignment = NSTextAlignmentCenter;
    [view_bg1 addSubview:list_1];
    
    
    UILabel * list_2 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 1.5, 7.5, list_x * 1, 20)];
    list_2.text = @"消费积分";
    list_2.textColor = navi_bar_bg_color;
    list_2.font = [UIFont systemFontOfSize:13];
    list_2.textAlignment = NSTextAlignmentCenter;
    [view_bg1 addSubview:list_2];
    
    
    UILabel * list_3 = [[UILabel alloc] initWithFrame:CGRectMake(5 + list_x * 2.5, 7.5, list_x * 1.5, 20)];
    list_3.text = @"日期";
    list_3.textColor = navi_bar_bg_color;
    list_3.font = [UIFont systemFontOfSize:13];
    list_3.textAlignment = NSTextAlignmentCenter;
    [view_bg1 addSubview:list_3];
    
    
    [view addSubview:view_bg1];
    
    return view;
}

- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 36.0f;
}








@end
